home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / lang / c--ex101 / rock / rock.c-- < prev    next >
Text File  |  1993-11-29  |  28KB  |  1,046 lines

  1. /*
  2.     NAME:  ROCK.C--
  3.     DESCRIPTION:  Multi-page display for 320x200 256 colours.
  4.                   Just a sketchy outline of a 'dodge the asteroids' game.
  5.                   Screen update speed could probably be increased.
  6.                   The ship's laser globs currently don't do anything, but
  7.                   will not go through objects.
  8.                   VGA display required.  Should work on most VGAs.
  9.                   80386+ cpu required for GUS sound support.
  10.                   To run with GUS support, YEA_GUS.EXE must be used, type
  11.                   the following at the DOS prompt for GUS support:
  12.                         YEA_GUS GUS ROCK.COM GUS
  13.     RUN FILE SIZE:  47112 bytes.
  14. */
  15.  
  16. ?use80286
  17. ?resize  TRUE
  18. ?resizemessage "Error resizing program memory block."
  19. ?ctrl_c  TRUE
  20. ?parsecommandline TRUE
  21.  
  22.  
  23. ?include "VIDEO.H--"
  24. ?include "VGA.H--"
  25. ?include "KEYCODES.H--"
  26. ?include "WRITE.H--"
  27. ?include "RANDOM.H--"
  28. ?include "SYSTEM.H--"
  29. ?include "DOS.H--"
  30. ?include "SOUND.H--"
  31. ?include "STRING.H--"
  32. ?include "GUS.H--"
  33. ?include "FILE.H--"
  34.  
  35.  
  36. ?define  LOGICALSCREENWIDTH    640
  37. ?define  LOGICALSCREENHEIGHT   200
  38. ?define  THECLEARCOLOR         0xFF
  39. ?include "VGAX.H--"
  40.  
  41. byte sound = TRUE;
  42. byte gusavailable = FALSE;
  43. byte guson = FALSE;
  44.  
  45. ?define  REPAIR_RATE  300  /* how many frames must be displayed before
  46.                               the sheild repairs itself by REPAIR_AMOUNT */
  47. ?define  REPAIR_AMOUNT 10
  48. ?define  MAX_SHIELD  63+63*4  /* maximum shield strength */
  49. ?define  SHIELD_LOW    16*4   /* max shield value to issue power warning */
  50.  
  51. ?define  DAMAGE_PER_PIXEL 1  /* damage incurred for each pixel of overlap */
  52. ?define  HEAL_PER_PIXEL 1    /* damage healed for each pixel of 'POWER' */
  53.  
  54. ?define  ROCKSPEED 20   // maximum speed for the rocks
  55.  
  56. ?define  STARCOLOR1     7
  57. ?define  STARCOLOR2     1
  58. ?define  STARCOLOR3     8
  59. ?define  BORDERCOLOR    2
  60. ?define  POWERCOLOR    32
  61. ?define  NUKECOLOR     31
  62.  
  63.  
  64. byte font = FROM "ROCK.FON";
  65.  
  66. ?define PALSIZE 256*3
  67. byte palette[PALSIZE] = FROM "ROCK.PAL";
  68. byte temp_palette[PALSIZE];
  69. byte holdR,holdG,holdB;
  70. ?define  DACSTART    16
  71. ?define  DACS        24
  72. ?define  CYCLESTART  DACSTART*3
  73.  
  74. byte leftdown,rightdown,updown,downdown;
  75. byte firedown;
  76. byte dofire;
  77. byte quit;
  78. byte set_temp_palette;
  79.  
  80. word oldkeyboardhandle[2];   /* address holder for old INT 0x9 handle */
  81.  
  82. /****** Bitmaps (these files can be edited with the use of TINYDRAW) ******/
  83. byte ship  = FROM "ship.iii";    // 226 bytes
  84. byte ship2 = FROM "ship.iii";    // used for collision detection
  85. byte rock1 = FROM "rock5.iii";   // 274 bytes
  86. byte rock2 = FROM "rock3.iii";   // 362 bytes
  87. byte rock3 = FROM "rock7.iii";   // 462 bytes
  88. byte rock4 = FROM "rock2.iii";   // 578 bytes
  89. byte rock5 = FROM "rock4.iii";   // 578 bytes
  90. byte rock6 = FROM "rock8.iii";   // 674 bytes
  91. byte rock7 = FROM "rock1.iii";   // 1682 bytes
  92. byte rock8 = FROM "rock6.iii";   // 3362 bytes
  93. byte rock9 = FROM "rock9.iii";   // 8218 bytes
  94. byte saturn = FROM "saturn.iii"; // 12882 bytes
  95. byte fire  = FROM "fire.iii";    // 62 bytes
  96. byte fire2 = FROM "fire.iii";    // used for collision detection
  97. byte powerpill = FROM "POWERPIL.III";   // 282 bytes
  98. byte nukepill = FROM "NUKEPIL.III";   // ? bytes
  99. /****** All bitmap are loaded at compile time ******/
  100.  
  101. word time;         // regenerate counter
  102. word count;
  103. word currentpage;
  104. word currentyadd;
  105. ?define PLANESIZE 64000/2
  106. word viewoffset;
  107. word shipsize,firesize;   // size holders for ship and fire images
  108. ?define XMEMOFFSET  40
  109. ?define XOFFSET     XMEMOFFSET*4
  110.  
  111. ?define MOVESIZE 2
  112. ?define MAXXMOVE 12
  113. ?define MINXMOVE -MAXXMOVE
  114. ?define MAXYMOVE 8
  115. ?define MINYMOVE -MAXYMOVE
  116. int xmove,ymove;
  117. int shield;
  118. ?define MAXXLOC 287+XOFFSET
  119. ?define MAXYLOC 191
  120. ?define MINXLOC 80+XOFFSET
  121. ?define MINYLOC 1
  122. int xloc,yloc;
  123.  
  124. ?define FADE_TIME 64
  125. ?define FINISH_DISTANCE 6666  // distance of finish
  126. word distancecount = 0;       // distance into game, also the score
  127. word freezecount;             // freeze addition of new things
  128.  
  129. // stars declarations
  130. ?define MAXSTARS1   10
  131. ?define STARSPEED1  12
  132. word starx1[MAXSTARS1],stary1[MAXSTARS1];
  133. ?define MAXSTARS2   15
  134. ?define STARSPEED2  8
  135. word starx2[MAXSTARS2],stary2[MAXSTARS2];
  136. ?define MAXSTARS3  45
  137. ?define STARSPEED3  4
  138. word starx3[MAXSTARS3],stary3[MAXSTARS3];
  139.  
  140.  
  141. // thing declarations
  142. ?define MAXTHINGS   25
  143. ?define MAXTHINGX  320+XOFFSET
  144. word thinglife[MAXTHINGS],thingmove[MAXTHINGS];
  145. enum { move_xandy,move_xrandom };
  146. word thingx[MAXTHINGS],thingy[MAXTHINGS];
  147. word thingxsize[MAXTHINGS],thingysize[MAXTHINGS];
  148. word thingxhit[MAXTHINGS],thingyhit[MAXTHINGS];
  149. word thingxinfo[MAXTHINGS],thingyinfo[MAXTHINGS];
  150. word thingimage[MAXTHINGS];
  151.  
  152. // fire declarations
  153. ?define MAXFIRE   20
  154. ?define MINFIREX  XOFFSET-10
  155. ?define FIRESPEED 10
  156. word firex[MAXFIRE],firey[MAXFIRE];
  157.  
  158. byte sphinx = "SPHINX Programming 1993";
  159.  
  160.  
  161. /*********** start of GUS support DATA **********/
  162.  
  163. ?define MUSICFILE "KLF.SND"
  164.  
  165. enum { samp_intro, samp_countdown, samp_atomboy, samp_bye, samp_music,
  166.        samp_fullpower, samp_shieldlow, samp_fire, SAMPLES };
  167.  
  168. dword dram;
  169. dword dramindex=0;    // index into GUS DRAM
  170. dword sample_start[SAMPLES];
  171. dword sample_end[SAMPLES];
  172. word  sample_freq[SAMPLES];
  173.  
  174. word gusvolume = 300;
  175. word gusvolume2 = 511;
  176. ?define ACTIVE_VOICES 14     // set number of voices 14..32
  177.  
  178. ?define BUFSIZE 4096
  179. byte samplebuf[BUFSIZE];
  180.  
  181. /************ end of GUS support DATA ***********/
  182.  
  183.  
  184.  
  185. interrupt keyboardhandle()
  186. {
  187. $ PUSH DS
  188. $ PUSH AX
  189. $ PUSH BX
  190. DS = CS;        /* make memory variables addressable */
  191. $ IN AL,0x60
  192. BL = TRUE;      // BL = press or release flag
  193. IF( AL >= 128 )
  194.     {AL -= 128;
  195.     BL = FALSE;
  196.     } 
  197. IF( AL == s_left )
  198.     leftdown = BL;
  199. else IF( AL == s_right )
  200.     rightdown = BL;
  201. else IF( AL == s_up )
  202.     updown = BL;
  203. ELSE IF( AL == s_down )
  204.     downdown = BL;
  205. ELSE IF( AL == s_space )
  206.     firedown = BL;
  207. ELSE IF( AL == s_home )
  208.     {updown = BL;
  209.     leftdown = BL;
  210.     }
  211. ELSE IF( AL == s_end )
  212.     {downdown = BL;
  213.     leftdown = BL;
  214.     }
  215. ELSE IF( AL == s_pageup )
  216.     {updown = BL;
  217.     rightdown = BL;
  218.     }
  219. ELSE IF( AL == s_pagedown )
  220.     {downdown = BL;
  221.     rightdown = BL;
  222.     }
  223. ELSE IF( AL == s_esc )
  224.     quit = TRUE;
  225. ELSE IF( AL == s_f12 )   // emergency abort!!!
  226.     {EATKEY();
  227.     EOI();
  228.     SETVIDEOMODE(vid_text80c);
  229.     SETINTVECT( ,KEYBOARD_INT,oldkeyboardhandle[2],oldkeyboardhandle[0]);
  230.     EXIT(-1);
  231.     }
  232. EATKEY();
  233. EOI();
  234. $ POP BX
  235. $ POP AX
  236. $ POP DS
  237. }
  238.  
  239.  
  240. int addthing (word life,move,y,xinfo,yinfo,image)
  241. {SI = 0;
  242. DI = MAXTHINGS*2;
  243. do {IF( thinglife[SI] == 0 )
  244.         DI = SI;
  245.     SI += 2;
  246.     } while( SI < MAXTHINGS*2 );
  247. IF( DI == MAXTHINGS*2 )    // maximum number of things already    
  248.     return(-1);
  249. thinglife[DI] = life;
  250. thingmove[DI] = move;
  251. thingy[DI] = y;
  252. SI = image;
  253. thingxhit[DI] = DSBYTE[SI]*4;    // xsize extracted from iii info 
  254. thingyhit[DI] = DSBYTE[SI+1];    // ysize extracted from iii info 
  255. thingxinfo[DI] = xinfo;
  256. thingyinfo[DI] = yinfo;
  257. BX = image;
  258. thingimage[DI] = BX;
  259. thingxsize[DI] = DSBYTE[BX]*4;
  260. thingysize[DI] = DSBYTE[BX+1];
  261. thingx[DI] = XOFFSET-thingxsize[DI];
  262. }
  263.  
  264.  
  265. void initializethings ()
  266. {
  267. DI = 0;
  268. do {thinglife[DI] = 0;
  269.     DI += 2;
  270.     } while( DI < MAXTHINGS*2 );
  271. thinglife[0] = 65535;
  272. thingx[0] = 0;
  273. thingy[0] = RAND()%80;
  274. thingxinfo[0] = 2;
  275. thingyinfo[0] = 0;
  276. thingimage[0] = #saturn;
  277. thingmove[0] = move_xandy;
  278. thingxsize[0] = saturn[0]*4;
  279. thingysize[0] = saturn[1];
  280. }
  281.  
  282.  
  283. void displaysoundstate ()
  284. {IF( sound == TRUE )
  285.     writestr_x(XOFFSET+26,56+40,"IBM [S]ound ON ",13,255);
  286. ELSE writestr_x(XOFFSET+26,56+40,"IBM [S]ound OFF",13,255);
  287. }
  288.  
  289.  
  290. void displaygusstate ()
  291. {IF( guson == TRUE )
  292.     writestr_x(XOFFSET+26,56+48,"[G]US Sound ON ",13,255);
  293. ELSE writestr_x(XOFFSET+26,56+48,"[G]US Sound OFF",13,255);
  294. }
  295.  
  296.  
  297. byte play_again ()
  298. byte j;
  299. {
  300. DI = 0;
  301. do {temp_palette[DI] = 0;
  302.     DI++;
  303.     } while( DI < PALSIZE );
  304. WAITVSYNC();
  305. SETVGADAC(0, ,PALSIZE, , ,#temp_palette);
  306. SETBORDERCOLOR(12);
  307. SETSCREENWIDTH( ,LOGICALSCREENWIDTH/8);
  308. CLEARSCREEN(0);
  309. WAITVSYNC();
  310. $ CLI
  311. SETSCREENOFFSET( ,XMEMOFFSET);
  312. $ STI
  313.  
  314. j = MAXSTARS1;
  315. loop(j)
  316.     putpixel_x(RAND()%320+XOFFSET,RAND()%200,STARCOLOR1);
  317. j = MAXSTARS2;
  318. loop(j)
  319.     putpixel_x(RAND()%320+XOFFSET,RAND()%200,STARCOLOR2);
  320. j = MAXSTARS3;
  321. loop(j)
  322.     putpixel_x(RAND()%320+XOFFSET,RAND()%200,STARCOLOR3);
  323. overicon_x(160+XOFFSET,70,DS,#saturn);
  324. overicon_x(60+XOFFSET,80,DS,#ship);
  325. overicon_x(240+XOFFSET,10,DS,#rock1);
  326. overicon_x(280+XOFFSET,50,DS,#rock2);
  327. overicon_x(200+XOFFSET,40,DS,#rock3);
  328.  
  329. writestr_x(XOFFSET+22,18,"ROCK DODGE  Version 1.0",7,255);
  330. writestr_x(XOFFSET+22,28,#sphinx,8,255);
  331. writestr_x(XOFFSET+16,56,"This Version is Freeware!",14,255);
  332.  
  333. IF( distancecount == 0 )
  334.     {writestr_x(25+XOFFSET,160-32,"INSTRUCTIONS:",1,255);
  335.     writestr_x(25+XOFFSET,160-20,"Use Cursor Keys to",4,255);
  336.     writestr_x(25+XOFFSET,160-12,"Maneuver the Ship Around",4,255);
  337.     writestr_x(25+XOFFSET,160-4,"All Asterioids and Planets.",4,255);
  338.     }
  339. ELSE IF( distancecount < FINISH_DISTANCE )
  340.     {writestr_x(30+XOFFSET,152,"Your Score Was:",1,255);
  341.     writedigits_x(3*8+XOFFSET+20,160,distancecount,4,255);
  342.     writestr_x(66+XOFFSET+20,160,"of a maximum of",5,255);
  343.     writedigits_x(22*8+XOFFSET-1+20,160,FINISH_DISTANCE+FADE_TIME,6,255);
  344.     }
  345. ELSE writestr_x(25+XOFFSET,160,"Congradulations!!!  You made it!",1,255);
  346. writestr_x(25+XOFFSET,180,"Press Any Key To Play or <ESC> to quit",0,255);
  347.  
  348. displaysoundstate();
  349.  
  350. IF( gusavailable )
  351.     displaygusstate();
  352.  
  353. IF( BIOSEKEYCHECK() != 0 )
  354.     BIOSEREADKEY();
  355.  
  356. fade_from_black();
  357.  
  358. loop()
  359.     {AX = BIOSEREADKEY();
  360.     IF( AL == 's' )
  361.         {sound = TRUE - sound;
  362.         displaysoundstate();
  363.         }
  364.     ELSE IF( AL == 'S' )
  365.         {sound = TRUE - sound;
  366.         displaysoundstate();
  367.         }
  368.     ELSE IF( AL == 'g' )
  369.         {IF( gusavailable )
  370.             {guson = TRUE - guson;
  371.             displaygusstate();
  372.             }
  373.         }
  374.     ELSE IF( AL == 'G' )
  375.         {IF( gusavailable )
  376.             {guson = TRUE - guson;
  377.             displaygusstate();
  378.             }
  379.         }
  380.     ELSE IF( AX == k_esc )
  381.         {IF( guson == TRUE )
  382.             playsample(samp_bye);
  383.         return(FALSE);
  384.         }
  385.     ELSE{
  386.         IF( guson == TRUE )
  387.             playsample(samp_countdown);
  388.         return(TRUE);
  389.         }
  390.     }
  391. }
  392.  
  393.  
  394.  
  395. void main ()
  396. byte play;
  397. word params,pcount;
  398. {
  399. params = PARAMCOUNT();
  400. if( params > 0 )
  401.     {pcount = 0;
  402.     do {
  403.         IF( STRCMP(PARAMSTR(pcount),"GUS") == 0 )
  404.             {AL = @ GETCPU();
  405.             IF( AL >= 3 )
  406.                 {gusavailable = TRUE;
  407.                 guson = TRUE;
  408.                 }
  409.             }
  410.         ELSE IF( STRCMP(PARAMSTR(pcount),"gus") == 0 )
  411.             {AL = @ GETCPU();
  412.             IF( AL >= 3 )
  413.                 {gusavailable = TRUE;
  414.                 guson = TRUE;
  415.                 }
  416.             }
  417.         pcount++;
  418.         } while( pcount < params );
  419.     }
  420.  
  421. IF( gusavailable )
  422.     gusinitialize(); 
  423.  
  424. fade_to_black();
  425. SETVIDEOMODE(vid_640x480_16);  // clear some vid ram
  426. IF( set320x200mode(FALSE) == FALSE )
  427.     {SETVIDEOMODE(vid_text80c);
  428.     WRITESTR("Unable to enter 256 colour video mode.\n");
  429.     EXIT(1);
  430.     }
  431.  
  432. IF( guson == TRUE )
  433.     playsample(samp_intro);
  434.  
  435. do {
  436.     play = play_again();
  437.     fade_to_black();
  438.     IF( play == TRUE )
  439.         playgame();
  440.     } while( play == TRUE );
  441.  
  442. SETVIDEOMODE( vid_text80c );
  443. WRITESTR(#sphinx);
  444. WRITELN();
  445. }
  446.  
  447.  
  448. void playgame ()
  449. {
  450. /*** start of initialize stuff ***/
  451. leftdown = FALSE;
  452. rightdown = FALSE;
  453. updown = FALSE;
  454. downdown = FALSE;
  455. firedown = FALSE;
  456. dofire = 0;
  457. quit = FALSE;
  458. set_temp_palette = FALSE;
  459. time = 0; 
  460. currentpage = 0;
  461. currentyadd = 0;
  462. viewoffset = PLANESIZE;
  463. xmove = 0;
  464. ymove = 0;
  465. shield = MAX_SHIELD;
  466. xloc = 200 + XOFFSET;
  467. yloc = 100;
  468. distancecount = 0;  
  469. freezecount = 200;  
  470. /*** end of initialize stuff ***/
  471.  
  472. SI = 0;
  473. do {temp_palette[SI] = 0;
  474.     SI++;
  475.     } while ( SI < PALSIZE );
  476. WAITVSYNC();
  477. SETVGADAC(0, ,PALSIZE, , ,#temp_palette);
  478. CLEARSCREEN(0);
  479. CLEARSCREEN(1);
  480. SETBORDERCOLOR(BORDERCOLOR);
  481. GETINTVECT(#oldkeyboardhandle,KEYBOARD_INT);   /* get old keyboard interrupt handle */
  482. SETINTVECT( ,KEYBOARD_INT,CS,#keyboardhandle); /* attach to keyboard interrupt */
  483. @ RANDOMIZE();
  484. initializestars();
  485. initializethings();
  486. DI = 0;
  487. do {firex[DI] = MINFIREX;
  488.     DI += 2;
  489.     } while( DI < MAXFIRE*2 );
  490. shipsize = DSBYTE[#ship+1] * DSBYTE[#ship] * 4;  /* get number of pixels
  491.                                                     in ship bitmap */ 
  492. DSWORD[#ship2] = DSWORD[#ship];
  493. firesize = DSBYTE[#fire+1] * DSBYTE[#fire] * 4;  /* get number of pixels
  494.                                                     in fire bitmap */ 
  495. DSWORD[#fire2] = DSWORD[#fire];
  496.  
  497. IF( guson == TRUE )
  498.     playsample(samp_music);
  499.  
  500. do {
  501.     viewoffset = PLANESIZE - viewoffset;
  502.     WAITVSYNC();
  503.     $ CLI
  504.     SETSCREENOFFSET( ,viewoffset+XMEMOFFSET);
  505.     $ STI
  506.  
  507.     IF( time > REPAIR_RATE )
  508.         {IF( shield < MAX_SHIELD )
  509.             {IF( shield < SHIELD_LOW )
  510.                IF( guson == TRUE )
  511.                    playsample(samp_shieldlow);
  512.             shield += REPAIR_AMOUNT;
  513.             }
  514.         time = 0;
  515.         }
  516.     time++;
  517.  
  518.     if( distancecount > 0 )      // check ship overlap
  519.         {BX = shipsize;
  520.         loop(BX)
  521.             {AL = ship2[1+BX];
  522.             IF( AL == POWERCOLOR )
  523.                 shield += HEAL_PER_PIXEL;
  524.             ELSE IF( AL == NUKECOLOR )
  525.                {$ PUSH BX 
  526.                IF( guson == TRUE )
  527.                    playsample(samp_atomboy);
  528.                $ POP BX 
  529.                DI = 0;
  530.                do {thinglife[DI] = 0;
  531.                    DI += 2;
  532.                    } while( DI < MAXTHINGS*2 );
  533.                }
  534.             ELSE IF( AL != THECLEARCOLOR )
  535.                 IF( AL != 0 ) 
  536.                     IF( AL != STARCOLOR1 ) 
  537.                         IF( AL != STARCOLOR2 ) 
  538.                             IF( AL != STARCOLOR3 ) 
  539.                                 {shield -= DAMAGE_PER_PIXEL;
  540.                                 IF( sound == TRUE )
  541.                                     {$ PUSH BX
  542.                                     SOUND(1000);
  543.                                     $ POP BX
  544.                                     }
  545.                                 }
  546.             }
  547.         IF( sound == TRUE )
  548.             NOSOUND();
  549.         }
  550.  
  551.     IF( shield < 0 )
  552.         {shield = 0;
  553.         quit = TRUE;}
  554.     ELSE IF( shield > MAX_SHIELD )
  555.         {IF( guson == TRUE )
  556.             playsample(samp_fullpower);
  557.         shield = MAX_SHIELD;
  558.         }
  559.  
  560.     BX = shipsize;                 //
  561.     loop(BX)                       //  copy the ship image
  562.         ship2[1+BX] = ship[1+BX];  //
  563.  
  564.     if( freezecount == 0 )
  565.         {if( distancecount < FINISH_DISTANCE - 600 )
  566.             {IF( RAND()%50 == 0 )
  567.                 addthing(1,move_xandy,RAND()%180,RAND()%ROCKSPEED+1,RAND()%6-2,#rock1);
  568.             IF( RAND()%50 == 0 )
  569.                 addthing(1,move_xrandom,RAND()%160,RAND()%ROCKSPEED+1,RAND()%6-2,#rock2);
  570.             IF( RAND()%50 == 0 )
  571.                 addthing(1,move_xandy,RAND()%160,RAND()%ROCKSPEED+1,RAND()%6-2,#rock3);
  572.             IF( RAND()%50 == 0 )
  573.                 addthing(1,move_xandy,RAND()%160,RAND()%ROCKSPEED+1,RAND()%6-2,#rock4);
  574.             IF( RAND()%100 == 0 )
  575.                 addthing(1,move_xandy,RAND()%160,RAND()%ROCKSPEED+1,RAND()%6-2,#rock5);
  576.             IF( RAND()%200 == 0 )
  577.                 addthing(1,move_xandy,RAND()%160,RAND()%6+1,RAND()%6-2,#rock6);
  578.             IF( RAND()%200 == 0 )
  579.                 addthing(1,move_xandy,RAND()%160,RAND()%3+1,RAND()%6-2,#rock7);
  580.             IF( RAND()%300 == 0 )
  581.                 addthing(1,move_xandy,RAND()%100,RAND()%3+1,RAND()%6-2,#rock8);
  582.             IF( RAND()%1000 == 0 )
  583.                 addthing(1,move_xandy,RAND()%100,RAND()%3+1,RAND()%6-2,#rock9);
  584.             IF( RAND()%500 == 0 )
  585.                 addthing(1,move_xandy,RAND()%160,RAND()%10+5,RAND()%6-2,#powerpill);
  586.             IF( RAND()%1000 == 0 )
  587.                 addthing(2,move_xandy,RAND()%160,RAND()%10+5,RAND()%6-2,#nukepill);
  588.             }
  589.         ELSE addthing(1,move_xandy,RAND()%160,RAND()%5+1,RAND()%6-2,#powerpill);
  590.         }
  591.     else freezecount--;
  592.  
  593.     holdR = palette[CYCLESTART];
  594.     holdG = palette[CYCLESTART+1];
  595.     holdB = palette[CYCLESTART+2];
  596.     @ COPYFAR(DS,#palette[CYCLESTART],DS,#palette[CYCLESTART+3],7*3);
  597.     palette[CYCLESTART+21] = holdR;
  598.     palette[CYCLESTART+21+1] = holdG;
  599.     palette[CYCLESTART+21+2] = holdB;
  600.  
  601.     AX = shield/4;
  602.     BL = AL;
  603.     IF( BL > 63 )
  604.         {palette[BORDERCOLOR*3] = 0;
  605.         palette[BORDERCOLOR*3+1] = BL-63;
  606.         }
  607.     ELSE{palette[BORDERCOLOR*3] = 63-BL;
  608.         palette[BORDERCOLOR*3+1] = 0;
  609.         }
  610.     palette[BORDERCOLOR*3+2] = 0;
  611.  
  612.     IF( distancecount <= 64 )   // fade on palette
  613.         {SI = 0;
  614.         DI = distancecount;
  615.         do {
  616.             AX = palette[SI] * DI / 64;
  617.             temp_palette[SI] = AX;
  618.             SI++;
  619.            } while ( SI < PALSIZE );
  620.         set_temp_palette = TRUE;
  621.         IF( sound == TRUE )
  622.             SOUND(100*distancecount+100);
  623.         }
  624.     ELSE IF( distancecount >= FINISH_DISTANCE )
  625.         {SI = 0;
  626.         DI = FINISH_DISTANCE-distancecount+64;
  627.         do {AX = palette[SI] * DI / 64;
  628.             temp_palette[SI] = AX;
  629.             SI++;
  630.            } while ( SI < PALSIZE );
  631.         set_temp_palette = TRUE;
  632.         }
  633.     ELSE IF( sound == TRUE )
  634.         NOSOUND();
  635.  
  636.     WAITVSYNC();
  637.     IF( set_temp_palette == TRUE )
  638.         SETVGADAC(0, ,PALSIZE, , ,#temp_palette);
  639.     ELSE{/* cycle the thrust palette */
  640.         SETVGADAC(DACSTART, ,DACS, , ,#palette[CYCLESTART]);
  641.         /* set shield colour */
  642.         SETVGADAC(BORDERCOLOR, ,3, , ,#palette[BORDERCOLOR*3]);
  643.         }
  644.     set_temp_palette = FALSE;
  645.     currentpage = 1 - currentpage;
  646.     currentyadd = 200 - currentyadd;
  647.  
  648.     CLEARSCREEN(currentpage);
  649.     dostars();
  650.     domovement();
  651.  
  652.     count = 0;
  653.     do {SI = count;
  654.         IF( thinglife[SI] != 0 )
  655.             overicon_x(thingx[SI],thingy[SI]+currentyadd,DS,thingimage[SI]);
  656.         count += 2;
  657.         } while( count < MAXTHINGS*2 );
  658.  
  659.     swapicon_x(xloc,yloc+currentyadd,DS,#ship2);
  660.  
  661.     count = 0;
  662.     do {SI = count;
  663.         IF( firex[SI] > MINFIREX )
  664.             {firex[SI] -= FIRESPEED;
  665.             BX = firesize;                 //
  666.             loop(BX)                       //  copy the fire image
  667.                 fire2[1+BX] = fire[1+BX];  //
  668.             swapicon_x(firex[SI],firey[SI]+currentyadd,DS,#fire2);
  669.             BX = firesize;
  670.             loop(BX)              // check fire overlap
  671.                 {AL = fire2[1+BX];
  672.                 IF( AL != THECLEARCOLOR )
  673.                     IF( AL != 0 ) 
  674.                         IF( AL != STARCOLOR1 ) 
  675.                             IF( AL != STARCOLOR2 ) 
  676.                                 IF( AL != STARCOLOR3 ) 
  677.                                     {SI = count;
  678.                                     firex[SI] = MINFIREX;
  679.                                     BX = 1;
  680.                                     }
  681.                 }
  682.             }
  683.         count += 2;
  684.         } while( count < MAXFIRE*2 );
  685.  
  686.     distancecount++;
  687.     IF( distancecount == FINISH_DISTANCE+FADE_TIME )
  688.         quit = TRUE;
  689.  
  690.     } while ( quit == FALSE );
  691.  
  692. IF( guson == TRUE )
  693.     GUSSTOP(samp_music);
  694.  
  695. IF( distancecount < FINISH_DISTANCE )
  696.     explode();
  697.  
  698. SETINTVECT( ,KEYBOARD_INT,oldkeyboardhandle[2],oldkeyboardhandle[0]);
  699. }
  700.  
  701.  
  702. void dostars ()
  703. {
  704. SI = 0;
  705. do {DI = SI+SI;
  706.     starx1[DI] += STARSPEED1; 
  707.     IF( starx1[DI] >= 320+XOFFSET )
  708.         {starx1[DI] = XOFFSET;
  709.         stary1[DI] = RAND()%200;}
  710.     putpixel_x(starx1[DI],stary1[DI]+currentyadd,STARCOLOR1);
  711.     SI++;
  712.     } while( SI < MAXSTARS1 );
  713.  
  714. SI = 0;
  715. do {DI = SI+SI;
  716.     starx2[DI] += STARSPEED2; 
  717.     IF( starx2[DI] >= 320+XOFFSET )
  718.         {starx2[DI] = XOFFSET;
  719.         stary2[DI] = RAND()%200;}
  720.     putpixel_x(starx2[DI],stary2[DI]+currentyadd,STARCOLOR2);
  721.     SI++;
  722.     } while( SI < MAXSTARS2 );
  723.  
  724. SI = 0;
  725. do {DI = SI+SI;
  726.     starx3[DI] += STARSPEED3; 
  727.     IF( starx3[DI] >= 320+XOFFSET )
  728.         {starx3[DI] = XOFFSET;
  729.         stary3[DI] = RAND()%200;}
  730.     putpixel_x(starx3[DI],stary3[DI]+currentyadd,STARCOLOR3);
  731.     SI++;
  732.     } while( SI < MAXSTARS3 );
  733. }
  734.  
  735.  
  736. void initializestars ()
  737. {SI = 0;
  738. do {DI = SI+SI;
  739.     starx1[DI] = RAND()%320;
  740.     stary1[DI] = RAND()%200;
  741.     SI++;
  742.     } while( SI < MAXSTARS1 );
  743. SI = 0;
  744. do {DI = SI+SI;
  745.     starx2[DI] = RAND()%320;
  746.     stary2[DI] = RAND()%200;
  747.     SI++;
  748.     } while( SI < MAXSTARS2 );
  749. SI = 0;
  750. do {DI = SI+SI;
  751.     starx3[DI] = RAND()%320+XOFFSET;
  752.     stary3[DI] = RAND()%200;
  753.     SI++;
  754.     } while( SI < MAXSTARS3 );
  755. }
  756.  
  757.  
  758. void CLEARSCREEN ()  // AX = page number
  759. {
  760. AX = AX * 32000;
  761. DI = AX+XMEMOFFSET;
  762. SETWRITEMASK( ,0xF);
  763. ES = VGA_SEG;
  764. SI = 0;
  765. AX = 0xFFFF;
  766. do {CX = 40;
  767.     $ REPZ
  768.     $ STOSW
  769.     DI += 80;
  770.     SI++;
  771.     } while( SI < 200 );
  772. }
  773.  
  774.  
  775. void explode ()
  776. word i;
  777. {i = 0;
  778. do {
  779.     AX = RAND()%3-1;
  780.     BX = AX;
  781.     WAITVSYNC();
  782.     SETSCREENOFFSET( ,BX+viewoffset+XMEMOFFSET);
  783.     IF( sound == TRUE )
  784.         SOUND(RAND()%10000+100);
  785.     i++;
  786.     } while( i < 25 );
  787. SETSCREENOFFSET( ,viewoffset+XMEMOFFSET);
  788. i = 0;
  789. do {
  790.     RAND();
  791.     BX = AX;
  792.     WAITVSYNC();
  793.     SETSCREENWIDTH( ,BX);
  794.     IF( sound == TRUE )
  795.         SOUND(RAND()%10000+100);
  796.     i++;
  797.     } while( i < 50 );
  798. IF( sound == TRUE )
  799.     NOSOUND();
  800. }
  801.  
  802.  
  803. void domovement ()
  804. {// start of movement of things
  805. count = 0;
  806. do {SI = count;
  807.     IF( thinglife[SI] != 0 )
  808.         {IF( thingmove[SI] == move_xandy )
  809.             {thingx[SI] += thingxinfo[SI];
  810.             thingy[SI] += thingyinfo[SI];}
  811.         ELSE IF( thingmove[SI] == move_xrandom )
  812.             thingx[SI] += RAND()%thingxinfo[SI];
  813.         IF( thingx[SI] > MAXTHINGX )
  814.             thinglife[SI] = 0;
  815.         IF( thingy[SI] > 1000 )
  816.             {thingy[SI] = 0;
  817.             -thingyinfo[SI];}
  818.         ELSE IF( thingy[SI]+thingysize[SI] > 200 )
  819.             {thingy[SI] = 200-thingysize[SI];
  820.             -thingyinfo[SI];}
  821.         }
  822.     count += 2;
  823.     } while( count < MAXTHINGS*2 );
  824.  
  825. // start of movement of player
  826. IF( leftdown == TRUE )
  827.     IF( xmove > MINXMOVE )
  828.         {IF( xmove > 0 )
  829.             xmove = 0;
  830.         ELSE xmove -= MOVESIZE;
  831.         } 
  832. IF( rightdown == TRUE )
  833.     IF( xmove < MAXXMOVE )
  834.         {IF( xmove < 0 )
  835.             xmove = 0;
  836.         ELSE xmove += MOVESIZE;
  837.         } 
  838. IF( rightdown == FALSE )
  839.         IF( leftdown == FALSE )
  840.             xmove = 0;
  841. IF( updown == TRUE )
  842.     IF( ymove > MINYMOVE )
  843.         {IF( ymove > 0 )
  844.             ymove = 0;
  845.         ELSE ymove -= MOVESIZE;
  846.         } 
  847. IF( downdown == TRUE )
  848.     IF( ymove < MAXYMOVE )
  849.         {IF( ymove < 0 )
  850.             ymove = 0;
  851.         ELSE ymove += MOVESIZE;
  852.         } 
  853. IF( updown == FALSE )
  854.     IF( downdown == FALSE )
  855.         ymove = 0;
  856. xloc += xmove;
  857. yloc += ymove;
  858. IF( xloc < MINXLOC )
  859.     xloc = MINXLOC;
  860. IF( xloc > MAXXLOC )
  861.     xloc = MAXXLOC;
  862. IF( yloc < MINYLOC )
  863.     yloc = MINYLOC;
  864. IF( yloc > MAXYLOC )
  865.     yloc = MAXYLOC;
  866. IF( firedown == TRUE )
  867.     {dofire = 1-dofire;
  868.     IF( dofire == 1 )
  869.         {SI = 0;
  870.         DI = MAXFIRE*2;
  871.         do {IF( firex[SI] <= MINFIREX )
  872.                 DI = SI; 
  873.             SI += 2;
  874.             } while( SI < MAXFIRE*2 );
  875.         IF( DI < MAXFIRE*2 )
  876.             {firex[DI] = xloc;
  877.             firey[DI] = yloc;
  878.             IF( guson == TRUE )
  879.                 playsample(samp_fire);
  880.             }
  881.         }
  882.     }
  883. ELSE dofire=0;
  884. }
  885.  
  886.  
  887. void fade_to_black ()
  888. {DI = 64;
  889. do {DI--;
  890.     SI = 0;
  891.     do {AX = palette[SI] * DI / 64;
  892.         temp_palette[SI] = AX;
  893.         SI++;
  894.         } while ( SI < PALSIZE );
  895.     $ PUSH DI
  896.     WAITVSYNC();
  897.     SETVGADAC(0, ,PALSIZE, , ,#temp_palette);
  898.     $ POP DI
  899.     IF( sound == TRUE )
  900.         SOUND(100*DI+100);
  901.     } while ( DI > 0 );
  902. IF( sound == TRUE )
  903.     NOSOUND();
  904. }
  905.  
  906.  
  907. void fade_from_black ()
  908. {DI = 0;
  909. do {
  910.     SI = 0;
  911.     do {AX = palette[SI] * DI / 64;
  912.         temp_palette[SI] = AX;
  913.         SI++;
  914.         } while ( SI < PALSIZE );
  915.     $ PUSH DI
  916.     WAITVSYNC();
  917.     SETVGADAC(0, ,PALSIZE, , ,#temp_palette);
  918.     $ POP DI
  919.     IF( sound == TRUE )
  920.         SOUND(100*DI+100);
  921.     DI++;
  922.     } while ( DI <= 64 );
  923. IF( sound == TRUE )
  924.     NOSOUND();
  925. }
  926.  
  927.  
  928. void writestr_x (word x,y,str; byte fgc,bgc)
  929. {
  930. SI = str;
  931. do {
  932.     $ PUSH SI
  933.     putletter_x(x,y,DSBYTE[SI]*64+#font,byte fgc,byte bgc);
  934.     $ POP SI
  935.     x += 7;
  936.     SI++;
  937.     } while( DSBYTE[SI] != 0 );
  938. }
  939.  
  940.  
  941. void writedigits_x (word x,y,number; byte fgc,bgc)
  942. {
  943. putletter_x(x,y,number/10000+'0'*64+#font,byte fgc,byte bgc);
  944. number = number % 10000;
  945. putletter_x(x+8,y,number/1000+'0'*64+#font,byte fgc,byte bgc);
  946. number = number % 1000;
  947. putletter_x(x+16,y,number/100+'0'*64+#font,byte fgc,byte bgc);
  948. number = number % 100;
  949. putletter_x(x+24,y,number/10+'0'*64+#font,byte fgc,byte bgc);
  950. number = number % 10;
  951. putletter_x(x+32,y,number+'0'*64+#font,byte fgc,byte bgc);
  952. }
  953.  
  954.  
  955.  
  956. /******************** GUS Sound CODE Starts **********************/
  957.  
  958.  
  959. void gusinitialize ()
  960. {
  961. dram = GUSSTATUS();
  962. IF( dram == 0 )
  963.     {WRITESTR("\nGUS not available.\n");
  964.     EXIT(1);
  965.     }
  966. WRITESTR("\nGUS found with ");
  967. WRITEWORD(dram);
  968. WRITESTR(" K DRAM.\n");
  969.  
  970. IF( dram < 1024 )
  971.     {WRITESTR("You should really upgrade to 1 MB.\n");
  972.     pressany();
  973.     }
  974. GUSRESET(ACTIVE_VOICES);
  975. WRITESTR("\nLOADING SAMPLES...\n");
  976. loadsample(samp_intro,"INTRO.SND",22050,GUS_2_COMP);
  977. loadsample(samp_countdown,"54321.SND",22050,GUS_2_COMP);
  978. loadsample(samp_bye,"BYE.SND",22050,GUS_2_COMP);
  979. loadsample(samp_atomboy,"ATOMBOY.SND",44100,GUS_2_COMP);
  980. loadsample(samp_fire,"HORN1.SND",22050,GUS_2_COMP);
  981. loadsample(samp_fullpower,"FULPOWER.SND",22050,GUS_2_COMP);
  982. loadsample(samp_shieldlow,"LOWPOWER.SND",22050,GUS_2_COMP);
  983. loadsample(samp_music,MUSICFILE,11025,GUS_2_COMP);
  984. }
  985.  
  986.  
  987. void loadsample (word sample,filename,frequency,format)
  988. word filehandle;
  989. word bytesread;
  990. {
  991. BX = sample+BX;
  992. sample_freq[BX] = frequency;
  993. BX = BX+BX;
  994. sample_start[BX] = dramindex;
  995.  
  996. filehandle = open(filename,F_READ);   /* open file for reading */
  997. IF(filehandle == 0)                    /* if file did not open */
  998.     {WRITESTR("Cannot Open File '");
  999.     WRITESTR(filename);
  1000.     WRITESTR("'!\n");
  1001.     pressany();
  1002.     guson = FALSE;
  1003.     return();
  1004.     }
  1005.  
  1006. do {
  1007.     bytesread = read(filehandle,#samplebuf,BUFSIZE);
  1008.     IF( bytesread > 0 )
  1009.         {GUSload(format, GUS_8_BIT,bytesread, DS,#samplebuf,dword dramindex);
  1010.         dramindex += bytesread;
  1011.         }
  1012.     } while( bytesread == BUFSIZE );
  1013.  
  1014. close(filehandle);
  1015.  
  1016. BX = sample+BX+BX;
  1017. sample_end[BX] = dramindex;
  1018. }
  1019.  
  1020.  
  1021. void playsample (word sample)
  1022. word looptype;
  1023. {GUSsetvolume(sample,gusvolume);
  1024. BX = sample + BX;
  1025. GUSsetfrequency(sample,sample_freq[BX]);
  1026. GUSsetbalance(sample,7);
  1027. BX = sample + BX + BX;
  1028. IF( sample == samp_music )
  1029.     looptype = GUS_LOOP_FORWARD;
  1030. ELSE looptype = GUS_LOOP_NONE;
  1031. GUSplay(sample, GUS_8_BIT, looptype, dword sample_start[BX],
  1032.                                      dword sample_start[BX],
  1033.                                      dword sample_end[BX] );
  1034. }
  1035.  
  1036. /******************** GUS Sound CODE ends **********************/
  1037.  
  1038.  
  1039. void pressany ()
  1040. {
  1041. WRITESTR("*** PRESS ANY KEY ***");
  1042. BIOSEREADKEY();
  1043. }
  1044.  
  1045.  
  1046. /* end of ROCK.C-- */